home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 6627 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.8 KB  |  50 lines

  1. Path: dispatch.news.demon.net!demon!fe-line.demon.co.uk
  2. From: faye@fe-line.demon.co.uk (Faye Pearson)
  3. Newsgroups: comp.lang.c,alt.bbs.proboard
  4. Subject: Re: Needed:  Centering Procedure that ignores escape sequences
  5. Date: Wed, 14 Feb 1996 23:05:25 GMT
  6. Organization: fe-line
  7. Message-ID: <31224b3d.1590682@158.152.254.254>
  8. References: <4fog4q$24v@news.mountain.net>
  9. NNTP-Posting-Host: fe-line.demon.co.uk
  10. X-NNTP-Posting-Host: fe-line.demon.co.uk
  11. X-Newsreader: Forte Agent .99c/16.141
  12.  
  13. matt.jenkins@westvirginia.com (Light Chaser) wrote:
  14.  
  15. >I spent a whole day trying to come up with a simple and small
  16. >centering routine.  I came up with one, but then ran into the problem
  17. >that I have to ignore escape sequences.  My BBS software, ProBoard,
  18. >supports only certain functions (which are listed at the end of this
  19. >message).  I want something where I can do:
  20. >center("\n\2This \3text \5contains \1escape \6sequences\t\n");
  21.  
  22. almost all proboards printf formatting escapes are single characters,
  23. if you wanted to just cope with that, you could use
  24.  
  25. void centre(char*string)
  26. {
  27. char *ptr;
  28. int esccount,xpos;
  29. char spaces[41];
  30.  
  31. for((esccount=0),(ptr=string-1);ptr=strchr(ptr+1,'\\');esccount++);
  32. xpos=40-strlen(string)/2-esccount;
  33. memset(spaces,' ',xpos-1);
  34. spaces[xpos]='\0';
  35. printf("%s%s",spaces,string); // Don't use GotoXY as it won't work for
  36.                               // ASCII users.
  37. }
  38.  
  39. This isn't a piece of code I have used, but I can't see why it
  40. wouldn't work...as long as the string to be output (-esc chars) is
  41. less than 80 characters long.
  42.  
  43.  
  44. Faye
  45. --
  46. Home of Fe-line Software,     http://www.win-uk.net/~fe-line
  47. PSN *UK* RC                   ftp://ftp.win-uk.net/pub/users/fe-line/
  48.                               mailto:sysops@fe-line.demon.co.uk
  49. ProBoard *UK* Registration & Support Site
  50.